package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.utils.CollUtils;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author yuqing
 * @since 2025-03-22
 */
@Api(tags = "我的课表相关业务接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {
    private final ILearningLessonService lessonService;

    @GetMapping("page")
    @ApiOperation("分页查询我的课表")
    public PageDTO<LearningLessonVO> queryMyLessonPage(PageQuery pageQuery) {
        return lessonService.queryMyLessonPage(pageQuery);
    }

    /**
     * 4、查询最近学习课程 (Day2- 作业2)
     * @returnz
     */
    @GetMapping("now")
    @ApiOperation("查询最近学习课程")
    public LearningLessonVO now() {
        return lessonService.now();
    }


    /*
    * 创建修改学习计划
    * */
    @PostMapping("/plans")
    @ApiOperation("创建修改学习计划")
    public void addPlans(@RequestBody LearningPlanDTO learningPlanDTO) {
        lessonService.addPlans(learningPlanDTO);
    }

    /*
     * 查询指定课程信息
     * */
    @GetMapping("/{courseId}")
    @ApiOperation("查询指定课程信息")
    public LearningLessonVO getLessonById(@PathVariable("courseId") Long courseId) {
        return (lessonService.getLessonById(courseId));
    }
    /**
     * 4、删除指定课程信息 (Day2- 作业2)
     * @return
     */
    @DeleteMapping("/{courseId}")
    @ApiOperation("删除指定课程信息")
    public void deleteCourseFromLesson(
            @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
        lessonService.deleteCourseFromLesson(null, CollUtils.singletonList(courseId));
    }
    /**
     * 5、统计课程学习人数 (Day2- 作业3)
     * @return
     */
    @ApiOperation("统计课程学习人数")
    @GetMapping("/{courseId}/count")
    public Integer countLearningLessonByCourse(
            @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId){
        return lessonService.countLearningLessonByCourse(courseId);
    }
    /**
     * 6、校验当前课程是否已经报名 (Day2- 作业4)
     * @return
     */
    @ApiOperation("校验当前课程是否已经报名")
    @GetMapping("/{courseId}/valid")
    public Long isLessonValid(
            @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
        return lessonService.isLessonValid(courseId);
    }
}
